﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
using Tauren.Business.DLL.Base;
using Tauren.Business.DLL.Resouces;
using Tauren.Business.Entity.Config;
using Tauren.Business.Entity.Const;
using Tauren.Business.Entity.Enum;
using Tauren.Business.Entity.Global;
using Tauren.Business.Entity.Input;
using Tauren.Business.Entity.Output;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Infrastructure.Globals;

namespace Tauren.Business.Service.Resources
{
    public class ResourcesService : Base.BaseService, IResourcesService
    {
        private IMenuResourcesBusiness business;
        public ResourcesService(IMenuResourcesBusiness baseDLL, IConnectionBLLBase connectionBLL) : base(baseDLL, connectionBLL, baseDLL)
        {
            this.ResourcesInfo = GetResources(GlobalConst.RESOURCES_FLAG_MODULE_KEY);
            this.JudePrmission(GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower());
            this.business = baseDLL;
        }
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="AutoID"></param>
        /// <returns></returns>
        public IResponseMessage Add(ModuleResouces_Input Data)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            if (Data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA));
            List<ModuleResouceTable> tables = business.GetByResCodeAndMoCoed(Data.ResCode, Data.MenuCode, Data.AutoID);
            if (tables.Any()) return GlobalErrorType.GLOBAL_REPEAT_CODE.Failure(this.CommonText(GlobalErrorType.GLOBAL_REPEAT_CODE));
            if (Data.ChildFieldValues is null || !Data.ChildFieldValues.Any()) return GlobalErrorType.GLOBAL_RES_LANGUAGE_REPEAT_ERROR.Failure(this.Resources(GlobalErrorType.GLOBAL_RES_LANGUAGE_REPEAT_ERROR));
            int Msg = 0;
            string lan = "";
            bool repeat = ValueRepeat(Data.ChildFieldValues, out Msg, out lan);
            long ResourcesID = LongCommon.Default.Create();
            if (!repeat) return Msg.Failure(string.Format(this.Resources(Msg), lan));
            Entity.Model.ModuleResouces resouces = new Entity.Model.ModuleResouces() { Enable = true, MenuCode = Data.MenuCode, ResCode = Data.ResCode, ResoucesType = Data.ResoucesType, Creatdate = DateTime.Now, Creator = Global.EmpId, Modifdate = DateTime.Now, Modifier = Global.EmpId, ResourceId = ResourcesID };
            using (TransactionScope ts = new TransactionScope())
            {
                long id = business.Add(resouces);
                if (id > 0)
                {
                    List<Entity.Model.ModuleResoucesRes> res = new List<Entity.Model.ModuleResoucesRes>();
                    foreach (var item in Data.ChildFieldValues)
                    {
                        res.Add(new Entity.Model.ModuleResoucesRes() { Language = item.Language, Value = item.Value, ResourceId = ResourcesID, Creator = Global.EmpId, Modifier = Global.EmpId, Creatdate = DateTime.Now, Modifdate = DateTime.Now });
                    }
                    bool b = business.Add(res);
                    if (b)
                    {
                        AddResources(Data.MenuCode, Data.ResCode, res);
                        ts.Complete();
                    }
                    return "".OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_SUCCESSINFO.ToString()));
                }
                else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));
            }

        }

        public IResponseMessage Config(string PageType)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<OutPutConfig> Fields = new List<OutPutConfig>();

            OutPutConfig config = new OutPutConfig();
            config.Label = this.Resources("autoId");
            config.FieldKey = "autoId";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.number;
            Fields.Add(config);
            config = new OutPutConfig();
            config.Label = this.Resources("resCode");
            config.FieldKey = "resCode";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = true;
            config.Editor = PageType != "view" && PageType != "edit";
            config.Required = PageType != "view" && PageType != "edit";
            Dictionary<object, object> rule = new Dictionary<object, object>();
            if (PageType != "view")
            {
                #region 添加验证规则

                rule.Add("required", true);
                rule.Add("message", this.Resources("rescodeerrormessage"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///长度
                rule = new Dictionary<object, object>();
                rule.Add("min", 1);
                rule.Add("max", 30);
                rule.Add("message", this.Resources("rescodelengthmessage"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
                ///正则
                rule = new Dictionary<object, object>();
                rule.Add("pattern", "^([a-zA-Z0-9]){1,30}$");
                rule.Add("message", this.Resources("rescoderegexhmessage"));
                rule.Add("trigger", "blur");
                config.Rules.Add(rule);
            }
            #endregion
            Fields.Add(config);
            config = new OutPutConfig();
            config.Label = this.Resources("menuCode");
            config.FieldKey = "menuCode";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.text;
            config.Show = false;
            Fields.Add(config);
            config = new OutPutConfig();
            config.Label = this.Resources("resoucesType");
            config.FieldKey = "resoucesType";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.parameter;
            config.Show = true;
            config.Editor = PageType != "view";
            config.Required = PageType != "view";
            config.Options = new List<Options>() {
                new Options { Label=this.Resources(LogType.Info.ToString().ToLower()),Value= LogType.Info.ToString().ToLower() },
                new Options { Label=this.Resources(LogType.Error.ToString().ToLower()),Value= LogType.Error.ToString().ToLower() },
                new Options { Label=this.Resources(LogType.Warning.ToString().ToLower()),Value= LogType.Warning.ToString().ToLower() }
            };
            if (PageType != "view")
            {
                rule = new Dictionary<object, object>();
                rule.Add("required", true);
                rule.Add("message", this.Resources("restypeerrormessage"));
                rule.Add("trigger", "change");
                config.Rules.Add(rule);
            }
            Fields.Add(config);

            config = new OutPutConfig();
            config.FieldKey = "childFieldValues";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.records;
            config.Show = true;
            config.Label = Resources("value");
            config.Editor = PageType != "view";
            //BuliedChildConfig(config.ChildFields, PageType);
            BuliedTableResConfig(config.Tables, PageType);
            Fields.Add(config);
            return Fields.Succeed();
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="AutoID"></param>
        /// <returns></returns>
        public IResponseMessage Delete(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            var data = business.Singe(AutoID);
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            data.Enable = false;
            data.IsDelete = true;
            data.Modifier = Global.EmpId;
            data.Modifdate = DateTime.Now;
            bool b = business.Edit(data);
            if (b)
            {
                RemoveResources(data.MenuCode, data.ResCode); return "".OnSucceed(this.Resources(GlobalErrorType.GLOBAL_DELETE_SUCCESSINFO));
            }
            else return GlobalErrorType.GLOBAL_DELETE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_DELETE_FAILURE));
        }

        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public IResponseMessage Editor(ModuleResouces_Input Data)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            if (Data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_INPUT_DATA));
            var data = business.Singe(Data.AutoID);
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            List<ModuleResouceTable> tables = business.GetByResCodeAndMoCoed(Data.ResCode, Data.MenuCode, Data.AutoID);
            if (tables.Any()) return GlobalErrorType.GLOBAL_REPEAT_CODE.Failure(this.CommonText(GlobalErrorType.GLOBAL_REPEAT_CODE));
            if (Data.ChildFieldValues is null || !Data.ChildFieldValues.Any()) return GlobalErrorType.GLOBAL_RES_LANGUAGE_REPEAT_ERROR.Failure(this.Resources(GlobalErrorType.GLOBAL_RES_LANGUAGE_REPEAT_ERROR));
            int Msg = 0;
            string lan = "";
            bool repeat = ValueRepeat(Data.ChildFieldValues, out Msg, out lan);
            if (!repeat) return Msg.Failure(string.Format(this.Resources(Msg), lan));
            data.Modifier = Global.EmpId;
            data.Modifdate = DateTime.Now;
            data.ResoucesType = Data.ResoucesType;
            using (TransactionScope ts = new TransactionScope())
            {
                bool b = business.Edit(data);
                if (b)
                {
                    List<Entity.Model.ModuleResoucesRes> res = new List<Entity.Model.ModuleResoucesRes>();
                    foreach (var item in Data.ChildFieldValues)
                    {
                        res.Add(new Entity.Model.ModuleResoucesRes() { Language = item.Language, Value = item.Value, ResourceId = data.ResourceId, Creator = Global.EmpId, Modifier = Global.EmpId, Creatdate = DateTime.Now, Modifdate = DateTime.Now });
                    }
                    b = business.Add(res);
                    if (b)
                    {
                        AddResources(Data.MenuCode, Data.ResCode, res);
                        ts.Complete();
                    }
                    return "".OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_SUCCESSINFO.ToString()));
                }
                else return GlobalErrorType.GLOBAL_SAVE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_SAVE_FAILURE));
            }
        }
        private bool ValueRepeat(List<ModuleResoucesRes_Input> ChildFieldValues, out int Msg, out string lan)
        {
            bool b = true;
            Msg = 0;
            lan = "";
            var groups = ChildFieldValues.GroupBy(o => o.Language).Select(n => new { Language = n.Key, cout = n.Count() });
            foreach (var item in groups)
            {
                if (item.cout > 1)
                {
                    b = false;
                    Msg = GlobalErrorType.GLOBAL_LANGUAGE_REPEAT_ERROR;
                    lan = item.Language;
                    break;
                }
            }
            return b;
        }

        public IResponseMessage Enable(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            var data = business.Singe(AutoID);
            if (data is null) return GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA.Failure(this.CommonText(GlobalErrorType.GLOBAL_NOT_FOUND_DB_DATA));
            data.Enable = !data.Enable;
            data.Modifier = Global.EmpId;
            data.Modifdate = DateTime.Now;
            bool b = business.Edit(data);
            if (b)
            {
                RemoveResources(data.MenuCode, data.ResCode);
                return "".OnSucceed(this.CommonText(data.Enable ? GlobalErrorType.GLOBAL_ENABLE_SUCCESSINFO : GlobalErrorType.GLOBAL_DISABLE_SUCCESSINFO));
            }
            else return data.Enable ? GlobalErrorType.GLOBAL_ENABLE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_ENABLE_FAILURE)) : GlobalErrorType.GLOBAL_DISABLE_FAILURE.OnSucceed(this.CommonText(GlobalErrorType.GLOBAL_DISABLE_FAILURE));
        }

        /// <summary>
        /// 根据主键获取数据
        /// </summary>
        /// <param name="AutoID"></param>
        /// <returns></returns>
        public IResponseMessage Get(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<ModuleResouceTable> modules = business.Get(AutoID);
            ModuleResouces_OutPut outPut = new ModuleResouces_OutPut();
            if (modules != null && modules.Any())
            {
                ModuleResouceTable module = modules.FirstOrDefault();
                ToViewModel(module, out outPut);
                if (!(outPut is null))
                {
                    outPut.ChildFieldValues = new List<ModuleResoucesRes_OutPut>();
                    modules.GroupBy(p => new { p.ResCode, p.AutoId }).ToList().ForEach(o =>
                    {
                        o.ToList().ForEach(chd =>
                        {
                            outPut.ChildFieldValues.Add(new ModuleResoucesRes_OutPut() { ResourceId = chd.ResourceId, Language = chd.Language, Value = chd.Value });
                        });
                    });
                }
            }
            else
            {
                outPut.ChildFieldValues = new List<ModuleResoucesRes_OutPut>() { new ModuleResoucesRes_OutPut() { Language = "", Value = "" } };
            }
            return outPut.Succeed();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="AutoID"></param>
        /// <returns></returns>
        public IResponseMessage Model(long AutoID)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            List<ModuleResouceTable> modules = business.Get(AutoID);
            List<OutPutModel> outPutModels = new List<OutPutModel>();
            BuliedValue(outPutModels, modules);
            return outPutModels.Succeed();
        }


        /// <summary>
        /// 分页获取表格数据
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        public IResponseMessage Pages(QueryModel queryModel)
        {
            if (!HavePermission) return ErrorType.BUSINESS_WITHOUT_PERMISSION.Failure(this.CommonText(ErrorType.BUSINESS_WITHOUT_PERMISSION));
            TableListModel<PageModuleResouceTable> tableListModel = new TableListModel<PageModuleResouceTable>();
            List<TableListHeaderModele> Headers = new List<TableListHeaderModele>();
            Headers.Add(new TableListHeaderModele() { Key = "rowNo", Name = CommonText("rowNo"), Width = 50, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "autoId", Name = CommonText("autoId"), Width = 70, Hide = true, Type = "primary_key", Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "menuCode", Name = Resources("menucode"), Width = 180, Type = "primary_name", Align = "center", SorTable = SortType.custom.ToString(), Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "resCode", Name = Resources("rescode"), Width = 180, IsOperation = true, SorTable = SortType.custom.ToString(), Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "resoucesType", Name = Resources("resoucestype"), Width = 100, IsTag = true, IsOtherStyle = true, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "language", Name = CommonText("languageType"), Width = 120, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "value", Name = Resources("value"), Filter = true });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Enable", Name = CommonText("thstate"), Width = 80, IsTag = true, Align = "center", SorTable = SortType.custom.ToString() });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creator", Name = CommonText("diccreator"), Width = 120, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "dic_Creatdate", Name = CommonText("diccreatdate"), Width = 160, Align = "center" });
            Headers.Add(new TableListHeaderModele() { Key = "action", Name = "操作", Width = 160, Align = "center" });
            List<AccountListModel> employeeListModels = new List<AccountListModel>();
            long Total = 0;
            List<PageModuleResouceTable> Data = business.Pages(queryModel, out Total);
            if (Data.Any())
            {
                Data.ForEach(o =>
                {
                    o.Dic_Enable = Resources(o.Enable ? GlobalConst.RESOURCES_CONTENT_ENABLE_KEY : GlobalConst.RESOURCES_CONTENT_DISABLE_KEY);
                    o.Language = Languages(GlobalConst.LANGUAGE_CONTENT_LANGUAGE_KEY);
                    o.Dic_Creator = EmpDictionary.ContainsKey(o.Creator) ? EmpDictionary[o.Creator] : "";
                    o.Dic_Modifier = EmpDictionary.ContainsKey(o.Modifier) ? EmpDictionary[o.Modifier] : "";
                    // o.Language = Resources(o.Language);
                    o.OtherType = o.ResoucesType == "info" ? "success" : o.ResoucesType == "error" ? "danger" : "warning";
                    o.ResoucesType = Resources(o.ResoucesType);
                    o.Row_Style = o.Enable ? "" : "danger";
                    o.Dic_Creatdate = o.Creatdate.Value.ToString(GlobalConst.DATE_FORMAT_SECONDS);
                    o.Operations = new List<SystemButton>();
                    if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
                    {
                        //BuliderButtons(o.Operations, o, ButtomType.add);
                        BuliderButtons(o.Operations, o.ResCode, o.AutoId, ButtomType.edit);
                        BuliderButtons(o.Operations, o.ResCode, o.AutoId, ButtomType.detaile);
                        BuliderButtons(o.Operations, o.ResCode, o.AutoId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                        BuliderButtons(o.Operations, o.ResCode, o.AutoId, ButtomType.delete);
                    }
                    else
                    {
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.edit.ToString()))
                            BuliderButtons(o.Operations, o.ResCode, o.AutoId, ButtomType.edit);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.detaile.ToString()))
                            BuliderButtons(o.Operations, o.ResCode, o.AutoId, ButtomType.detaile);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && (o.Value == ButtomType.disable.ToString() || o.Value == ButtomType.enable.ToString())))
                            BuliderButtons(o.Operations, o.ResCode, o.AutoId, !o.Enable ? ButtomType.enable : ButtomType.disable);
                        if (Buttons.Any(o => o.Location == ButtomLocation.center.ToString() && o.Value == ButtomType.delete.ToString()))
                            BuliderButtons(o.Operations, o.ResCode, o.AutoId, ButtomType.delete);
                    }
                });
            }
            tableListModel.Body = Data;
            tableListModel.Total = Total;
            tableListModel.Header = Headers;
            if (Global.IsAdmin && (Buttons is null || !Buttons.Any()))
            {
                BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
            }
            else
            {
                if (Buttons.Any(o => o.Value == ButtomType.add.ToString()))
                    BuliderButtons(tableListModel.Operations, "", 0, ButtomType.add);
            }
            return tableListModel.Succeed();
        }
        /// <summary>
        /// 创建子数据模块
        /// </summary>
        /// <param name="outPutModels"></param>
        /// <param name="modules"></param>
        private void BuliedChildValue(List<ChildOutPutMode> ChildVlaues, List<ModuleResouceTable> modules)
        {
            if (modules != null && modules.Any())
            {
                modules.GroupBy(p => new { p.ResCode, p.AutoId }).ToList().ForEach(o =>
                {
                    o.ToList().ForEach(chd =>
                    {
                        List<OutPutModel> outps = new List<OutPutModel>();
                        var outPut1 = new OutPutModel();
                        outPut1.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
                        outPut1.FieldKey = "language";
                        outPut1.FieldValue = chd.Language;
                        outps.Add(outPut1);
                        outPut1 = new OutPutModel();
                        outPut1.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
                        outPut1.FieldKey = "value";
                        outPut1.FieldValue = chd.Value;
                        outps.Add(outPut1);
                        ChildVlaues.Add(new ChildOutPutMode() { Vlaues = outps });
                    });
                });
            }
            else
            {
                List<OutPutModel> outps = new List<OutPutModel>();
                var outPut1 = new OutPutModel();
                outPut1.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
                outPut1.FieldKey = "language";
                outPut1.FieldValue = "zh-cn";
                outps.Add(outPut1);
                outPut1 = new OutPutModel();
                outPut1.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
                outPut1.FieldKey = "value";
                outPut1.FieldValue = "";
                outps.Add(outPut1);
                ChildVlaues.Add(new ChildOutPutMode() { Vlaues = outps });
            }
        }
        /// <summary>
        /// 创建主数据模块
        /// </summary>
        /// <param name="outPutModels"></param>
        /// <param name="modules"></param>
        private void BuliedValue(List<OutPutModel> outPutModels, List<ModuleResouceTable> modules)
        {
            ModuleResouceTable module = null;
            if (modules != null && modules.Any())
            {
                module = modules.FirstOrDefault();
            }
            OutPutModel outPut = new OutPutModel();
            outPut.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            outPut.FieldKey = "auotId";
            outPut.FieldValue = module is null ? 0 : module.AutoId;
            outPutModels.Add(outPut);
            outPut = new OutPutModel();
            outPut.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            outPut.FieldKey = "resCode";
            outPut.FieldValue = module is null ? "" : module.ResCode;
            outPutModels.Add(outPut);
            outPut = new OutPutModel();
            outPut.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            outPut.FieldKey = "menuCode";
            outPut.FieldValue = module is null ? "" : module.MenuCode;
            outPutModels.Add(outPut);
            outPut = new OutPutModel();
            outPut.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            outPut.FieldKey = "resoucesType";
            outPut.FieldValue = module is null ? 0 : module.AutoId;
            outPutModels.Add(outPut);
            outPut = new OutPutModel();
            outPut.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            outPut.FieldKey = "childFields";
            BuliedChildValue(outPut.ChildFields, modules);
            outPutModels.Add(outPut);
        }

        private void BuliedChildConfig(List<OutPutConfig> Fields, string pageType)
        {
            var config = new OutPutConfig();
            config.Label = this.Resources("language");
            config.FieldKey = "language";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.parameter;
            config.Show = true;
            config.Editor = pageType != "view";
            config.Options = new List<Options>() {
                new Options { Label=this.Languages("en"),Value= "en" },
                new Options { Label=this.Languages("zh-cn"),Value="zh-cn"},
            };
            Dictionary<object, object> rule = new Dictionary<object, object>();
            rule.Add("required", true);
            rule.Add("message", this.Resources("resLaneErrorMessage"));
            rule.Add("trigger", "change");
            if (pageType != "view")
                config.Rules.Add(rule);
            Fields.Add(config);
            config = new OutPutConfig();
            config.Label = this.Resources("value");
            config.FieldKey = "value";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            config.ControlType = ControlType.textarea;
            config.Show = true;
            config.Editor = pageType != "view";
            ///长度
            rule = new Dictionary<object, object>();
            rule.Add("min", 0);
            rule.Add("max", 250);
            rule.Add("message", this.Resources("ResValueLengthMsg"));
            rule.Add("trigger", "blur");
            if (pageType != "view")
                config.Rules.Add(rule);
            Fields.Add(config);
            config = new OutPutConfig();
            config.FieldKey = "template";
            config.MenuCode = GlobalConst.RESOURCES_FLAG_MODULE_KEY.ToLower();
            Fields.Add(config);
        }

        protected override void BuliedTableResConfig(List<TableListHeaderModele> Headers, string pageType)
        {
            Dictionary<object, object> rule = new Dictionary<object, object>();
            rule.Add("required", true);
            rule.Add("message", this.Resources("reslaneerrormessage"));
            rule.Add("trigger", "change");
            Headers.Add(new TableListHeaderModele()
            {
                Key = "language",
                Name = Resources("language"),
                Align = "left",
                Options = this.Options,
                Rules = pageType != "view" ? new List<Dictionary<object, object>>() { rule } : new List<Dictionary<object, object>>(),
                Show = true,
                Editor = pageType != "view",
                ControlType = ControlType.parameter,
            });
            ///长度
            rule = new Dictionary<object, object>();
            rule.Add("min", 0);
            rule.Add("max", 250);
            rule.Add("message", this.Resources("resvaluelengthmsg"));
            rule.Add("trigger", "blur");
            Headers.Add(new TableListHeaderModele()
            {
                Key = "value",
                Name = Resources("value"),
                IsOperation = true,
                Align = "center",
                Rules = pageType != "view" ? new List<Dictionary<object, object>>() { rule } : new List<Dictionary<object, object>>(),
                Show = true,
                Editor = pageType != "view",
                ControlType = ControlType.textarea
            });
        }

        public IResponseMessage Template(string key)
        {
            return new ModuleResoucesRes_OutPut() { Language = "", Value = "" }.Succeed();
        }

    }
}
